home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_visual.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.2 KB  |  107 lines

  1. //
  2. // "$Id: Fl_visual.cxx,v 1.7 1999/01/07 19:17:32 mike Exp $"
  3. //
  4. // Visual support for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Set the default visual according to passed switches:
  27.  
  28. #include <config.h>
  29. #include <FL/Fl.H>
  30. #include <FL/x.H>
  31.  
  32. #ifdef WIN32
  33. int Fl::visual(int flags) {
  34.   fl_GetDC(0);
  35.   if (flags & FL_DOUBLE) return 0;
  36.   if (!(flags & FL_INDEX) &&
  37.     GetDeviceCaps(fl_gc,BITSPIXEL) <= 8) return 0;
  38.   if ((flags & FL_RGB8) && GetDeviceCaps(fl_gc,BITSPIXEL)<24) return 0;
  39.   return 1;
  40. }
  41. #else
  42.  
  43. #if USE_XDBE
  44. #include <X11/extensions/Xdbe.h>
  45. #endif
  46.  
  47. static int test_visual(XVisualInfo& v, int flags) {
  48.   if (v.screen != fl_screen) return 0;
  49.   if (!(flags & FL_INDEX)) {
  50.     if (v.c_class != StaticColor && v.c_class != TrueColor) return 0;
  51.     if (v.depth <= 8) return 0; // fltk will work better in colormap mode
  52.   }
  53.   if (flags & FL_RGB8) {
  54.     if (v.depth < 24) return 0;
  55.   }
  56.   // for now, fltk does not like colormaps of more than 8 bits:
  57.   if ((v.c_class&1) && v.depth > 8) return 0;
  58. #if USE_XDBE
  59.   if (flags & FL_DOUBLE) {
  60.     static XdbeScreenVisualInfo *xdbejunk;
  61.     if (!xdbejunk) {
  62.       int event_base, error_base;
  63.       if (!XdbeQueryExtension(fl_display, &event_base, &error_base)) return 0;
  64.       Drawable root = RootWindow(fl_display,fl_screen);
  65.       int numscreens = 1;
  66.       xdbejunk = XdbeGetVisualInfo(fl_display,&root,&numscreens);
  67.       if (!xdbejunk) return 0;
  68.     }
  69.     for (int j = 0; ; j++) {
  70.       if (j >= xdbejunk->count) return 0;
  71.       if (xdbejunk->visinfo[j].visual == v.visualid) break;
  72.     }
  73.   }
  74. #endif
  75.   return 1;
  76. }
  77.  
  78. int Fl::visual(int flags) {
  79. #if USE_XDBE == 0
  80.   if (flags & FL_DOUBLE) return 0;
  81. #endif
  82.   fl_open_display();
  83.   // always use default if possible:
  84.   if (test_visual(*fl_visual, flags)) return 1;
  85.   // get all the visuals:
  86.   XVisualInfo vTemplate;
  87.   int num;
  88.   XVisualInfo *visualList = XGetVisualInfo(fl_display, 0, &vTemplate, &num);
  89.   // find all matches, use the one with greatest depth:
  90.   XVisualInfo *found = 0;
  91.   for (int i=0; i<num; i++) if (test_visual(visualList[i], flags)) {
  92.     if (!found || found->depth < visualList[i].depth)
  93.       found = &visualList[i];
  94.   }
  95.   if (!found) {XFree((void*)visualList); return 0;}
  96.   fl_visual = found;
  97.   fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
  98.                 fl_visual->visual, AllocNone);
  99.   return 1;
  100. }
  101.  
  102. #endif
  103.  
  104. //
  105. // End of "$Id: Fl_visual.cxx,v 1.7 1999/01/07 19:17:32 mike Exp $".
  106. //
  107.